import React from "react";
import styles from './uc-loading.module.css'
import propsTypes from 'prop-types'

export default class UcLoading extends React.Component {

    state = {
        el: null,
    }

    static defaultProps = {
        spinning: false,
        tip: '加载中',
        delay: 0
    }
    static propsTypes = {
        spinning: propsTypes.bool,
        tip: propsTypes.string,
        delay: propsTypes.number
    }

    componentDidMount() {
        if (this.props.delay > 0) {
            setTimeout(() => {
                this.setState({ el: <div className={styles.spinner} ></div> })
            }, this.props.delay)
        } else {
            this.setState({ el: <div className={styles.spinner}></div> })
        }
    }
    render() {
        return this.props.spinning ? this.state.el : null
    }
}